
using System;
using System.Collections.Generic;
using NUnit.Framework;

namespace SanFS.MediaChangerLibrary
{
#if false
	
	[TestFixture]
	public class TestSqliteDataStore
	{
		SqliteDataStore mDbConn;
		
		List<Disc> discs;
		List<DiscFile> files;
		List<StorageElement> elements;
		
		Random mRandom;
		//EDiscType Type, bool Rewriteable, EDiscStatus DiscStatus, ulong TotalSize, 
		//					ulong FreeSpace, int MaxWriteSpeed, Guid Uuid, int Version,
		//					List<IDiscFile> Files, int NumSessions
		[SetUp]
		public void SetUp() {
			/**
			mRandom = new Random(Environment.TickCount);
			Console.WriteLine("Connecting to db store");
			files = new List<IDiscFile>();
			for(int i = 0;i<50;i++) {
				files.Add(new DiscFile(
			}
			Disc aDisc = new Disc(EDiscType.DVDR_DL, true, EDiscStatus.Blank, 12345678978901234L, 
								432924982809208L, 32, Guid.NewGuid(), 1,files, 1);
								
			**/
			Console.WriteLine("Creating db store");
			mDbConn = new SqliteDataStore("URI=file::memory:,version=3");
			mDbConn.Connect();		
		
		}
		
		[Test]
		public void TestAddAndRetrieveDiscFileShouldBeEqual() {
			
			// Create discfile object
			Guid Uuid = Guid.NewGuid();
			UInt64 TotalSize = 132230924350984435L;
			Int32 TotalChunks = 30;
			String Path = "/foo/bar";
			Int32 ChunkNumber = 1;
			UInt64 ChunkSize = 213098L;
			UInt64 ChunkOffset = 2332L;
			
			Console.WriteLine("Creating DiscFile");
			DiscFile mRefFile = new DiscFile(Uuid, TotalSize, TotalChunks, Path, ChunkNumber, ChunkSize, ChunkOffset);
			
			Console.WriteLine("Adding DiscFile to db");
			mDbConn.AddDiscFile(mRefFile,Guid.NewGuid());
			
			Console.WriteLine("Retrieving DiscFile from db");
			DiscFile mTestFile = (DiscFile) mDbConn.GetDiscFile(Uuid.ToString(), ChunkNumber);
			
			
			// Check and make sure everything came out okay
			Console.WriteLine("Comparing local object and db result");
			Assert.AreEqual(mTestFile.Uuid, Uuid);
			Assert.AreEqual(mTestFile.TotalSize, TotalSize);
			Assert.AreEqual(mTestFile.TotalChunks, TotalChunks);
			Assert.AreEqual(mTestFile.Path, Path);
			Assert.AreEqual(mTestFile.ChunkNumber, ChunkNumber);
			Assert.AreEqual(mTestFile.ChunkOffset, ChunkOffset);
			Assert.AreEqual(mTestFile.ChunkSize, ChunkSize);
						
			
		}
		
		public void TestAddAndRetrieveStorageElementShouldBeEqual() {
			StorageElement mStorageElement = new StorageElement(55,ElementType.DataTransfer,false);
			
			Console.WriteLine("Adding StorageElement to db");
			mDbConn.AddStorageElement(mStorageElement);
			
			Console.WriteLine("Retrieving StorageElement from db");
			List<IStorageElement> mStorageElementsRetrieved = mDbConn.LoadStorageElements();
			
			//Check and make sure everything came out okay
			Assert.AreEqual(mStorageElementsRetrieved.Count, 1);
			Console.WriteLine("Number of elements returned = {0}",mStorageElementsRetrieved.Count);
			StorageElement foo = (StorageElement)mStorageElementsRetrieved[0];
			Assert.AreEqual(mStorageElement.Empty, foo.Empty);
			Assert.AreEqual(mStorageElement.Slot, foo.Slot);
			Assert.AreEqual(mStorageElement.Type, foo.Type);
			
		}
		 
		 

		[TearDown]
		public void TearDown() {
			Console.WriteLine("Disconnectiong from db store");
			mDbConn.Disconnect();
      	}
	}
#endif
}
